package com.tanggh.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public abstract class GenericAction extends ActionSupport implements ServletRequestAware,ServletResponseAware,SessionAware {
	private static final long serialVersionUID = 1L;
	
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected Map<String, Object> session;
	
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	
	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	@Override
	public void setSession(Map<String, Object> map) {
		this.session = map;
	}
	
	protected String getString(String name){
		return request.getParameter(name);
	}
	
	protected int getInt(String name) {
		String value = request.getParameter(name);
		return Integer.parseInt(value);
	}
	
	protected String getIP() {
		return request.getRemoteAddr();
	}
	
	protected void write(String str) {
		try {
			PrintWriter out = response.getWriter();
			out.print(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
